<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>迷你号归属地查询</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f4f4f4;
        }
        .container {
            background-color: white;
            padding: 40px;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            text-align: center;
        }
        input[type="text"] {
            padding: 10px;
            width: 250px;
            margin-bottom: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        button {
            padding: 10px 20px;
            background-color: green;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }
        button:hover {
            background-color: darkgreen;
        }
        .card {
            margin-top: 20px;
            padding: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            width: 300px;
            margin-left: auto;
            margin-right: auto;
            background-color: #f9f9f9;
        }
        .error {
            color: red;
        }
        p {
            color: gray;
        }
    </style>
</head>
<body>

<div class="container">
    <h1>查询迷你号地址归属地信息工具</h1>
    <form method="get">
        <label for="uinInput">请输入迷你号:</label>
        <br>
        <input type="text" id="uinInput" name="uin" required>
        <br>
        <button type="submit">查询</button>
    </form>

    <?php
    $blacklist = ['1838583099', '1097650501'];

    // 检查用户是否提交了表单
    if (isset($_GET['uin'])) {
        $uin = htmlspecialchars($_GET['uin']); // 获取并安全化用户输入的 UIN

        // 检查 UIN 是否在黑名单中
        if (in_array($uin, $blacklist)) {
            echo '<div class="card error">';
            echo "<h3>此 UIN 被列入黑名单，无法查询。</h3>";
            echo '</div>';
        } else {
            // 构造接口 URL，使用用户输入的 UIN
            $url = "http://operate.mini1.cn:8080/miniw/user_ext?act=get_user_addr&op_uin=" . $uin . "&time=1691276368&auth=f0d95bc1b8a84f9546496b7b5eecf9e5&s2t=1691275202&uin=1247832469&ver=1.32.0&apiid=81&lang=0&country=CN&s7e=1=f3ff4";

            // 初始化 CURL
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

            // 执行 CURL 请求
            $response = curl_exec($ch);
            $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            curl_close($ch);

            // 检查请求是否成功
            if ($response !== false && $httpCode == 200) {
                // 尝试通过字符串匹配获取数据
                preg_match('/\["addr"\]="([^"]*)"/', $response, $addrMatches);
                preg_match('/\["caddr"\]="([^"]*)"/', $response, $caddrMatches);
                preg_match('/\["uin"\]="([^"]*)"/', $response, $uinMatches);

                // 如果匹配成功
                if (!empty($addrMatches) && !empty($caddrMatches) && !empty($uinMatches)) {
                    echo '<div class="card">';
                    echo "<h3>查询结果:</h3>";
                    echo "省份 : " . htmlspecialchars($addrMatches[1]) . "<br>";
                    echo "市区 : " . htmlspecialchars($caddrMatches[1]) . "<br>";
                    echo "迷你号 : " . htmlspecialchars($uinMatches[1]) . "<br>";
                    echo '</div>';
                } else {
                    // 如果解析失败，显示完整的响应内容
                    echo '<div class="card error">';
                    echo "<h3>获取信息失败</h3>";
                    echo '</div>';
                }
            } else {
                // 请求失败，显示完整的响应内容
                echo '<div class="card error">';
                echo "<h3>获取信息失败，请检查网络连接或接口返回内容：</h3>";
                echo "<pre>" . htmlspecialchars($response) . "</pre>";
                echo '</div>';
            }
        }
    }
    ?>

    <a href="http://gitee.com/sansjtw"><p>© SansJtw</p></a>
</div>

</body>
</html>
